﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MTO.Framework.Common
{
    public static class IntExtensions
    {
        /// <summary>
        /// Sert à convertir un chiffre en sont équivalent en lettre. Ex: 1 = A, 26 = Z, 27 = AA, 28 = AB, etc.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string ConvertToLetterEquivalent(this int value)
        {
            int dividend = value;
            string columnName = String.Empty;
            int modulo;

            while (dividend > 0)
            {
                modulo = (dividend - 1) % 26;
                columnName = Convert.ToChar(65 + modulo).ToString() + columnName;
                dividend = (int)((dividend - modulo) / 26);
            }

            return columnName;
        }
    }
}
